import { ApiProperty } from '@nestjs/swagger';

/**
 * 通用响应 DTO
 */
export class ResponseDto<T = any> {
  @ApiProperty({ description: '状态码', example: 200 })
  code: number;

  @ApiProperty({ description: '响应消息', example: '操作成功' })
  message: string;

  @ApiProperty({ description: '响应数据' })
  data?: T;

  @ApiProperty({ description: '时间戳', example: 1640995200000 })
  timestamp: number;

  constructor(code: number, message: string, data?: T) {
    this.code = code;
    this.message = message;
    this.data = data;
    this.timestamp = Date.now();
  }
}

/**
 * 分页响应 DTO
 */
export class PaginationResponseDto<T = any> extends ResponseDto<{
  items: T[];
  total: number;
  page: number;
  limit: number;
}> {
  @ApiProperty({
    description: '分页数据',
    type: 'object',
    properties: {
      items: { type: 'array', description: '数据列表' },
      total: { type: 'number', description: '总数' },
      page: { type: 'number', description: '当前页码' },
      limit: { type: 'number', description: '每页数量' },
    },
  })
  data: {
    items: T[];
    total: number;
    page: number;
    limit: number;
  };
}